<template>
	<view>
		<!-- 搜索 -->
		<view class='pos'>
			<s-search @tap='pos'></s-search>
		</view>
		<!-- 轮播图 -->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true"
			indicator-color="rgb(255,255,255)">
			<swiper-item v-for="(item,i) in swiperList" :key="item.goods_id">
				<navigator class="swiper-item" :url="'/subpkg/goods_detail/goods_detail?good_id='+item.goods_id">
					<image :src="item.image_src"></image>
				</navigator>
			</swiper-item>
		</swiper>
		<!-- 分类导航 -->
		<view class="navList">
			<view v-for="(ele,i) in navList" :key="ele.goods_id" @click="navg(i)">
				<image :src="ele.image_src"></image>
			</view>
		</view>
		<!-- 商品列表 -->
		<view>
			<view v-for="(item,i) in floorList" :key="i">
				<!-- 标题 -->

				<image :src="item.floor_title.image_src" class="img_title"></image>
				<!-- 图片 -->
				<view class='flex'>
					<navigator :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src"
							:style="{width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
					</navigator>
					<view class="floor_right">
						<navigator :url="item1.url" v-for="(item1,i) in item.product_list" :key="i" v-if="i !== 0">
							<image :src="item1.image_src" mode="widthFix" :style="{width:item1.image_width+'rpx'}">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swiperList: [], //轮播图数据
				navList: [], //分类导航数据
				floorList: []
			};
		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		},
		methods: {
			async getSwiperList() {
				const { data: res } = await uni.$http.get('public/v1/home/swiperdata')

				console.log('轮播图\n', res);
				if (res.meta.status !== 200) return uni.$showMsg
				this.swiperList = res.message
				uni.$showMsg('数据请求成功')
			},
			async getNavList() {
				const { data: res } = await uni.$http.get('public/v1/home/catitems')
				console.log('导航数据\n', res);
				if (res.meta.status !== 200) return uni.$showMsg
				this.navList = res.message
				uni.$showMsg('数据请求成功')
			},
			navg(i) {
				if (i === 0) {
					uni.switchTab({
						url: '/pages/cate/cate'
					})
				}
				console.log(i)
			},
			async getFloorList() {
				const { data: res } = await uni.$http.get('public/v1/home/floordata')
				if (res.meta.status !== 200) return uni.$showMsg()
				console.log('楼层数据\n', res);
				res.message.forEach(floor => {
					floor.product_list.forEach(prod => {
						prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
					})
				})
				this.floorList = res.message
			},
			pos() {
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			}
		}
	}

</script>

<style lang="scss">
	// 搜索
	.pos {
		position: sticky;
		top: 0;
		z-index: 99;
	}

	swiper {
		height: 330repx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.navList {
		display: flex;
		justify-content: space-around;
		margin: 15px 0;

		image {
			width: 128rpx;
			height: 140rpx;
		}
	}

	// 楼层
	.img_title {
		width: 100%;
		height: 60rpx;
	}

	.flex {
		display: flex;
		padding: 5rpx;

		.floor_right {
			flex: 1;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-around;
		}
	}

</style>

